//
////
////  IJSImageAPIManager.m
////  JSPhotoSDK
////
////  Created by shan on 2017/5/31.
////  Copyright © 2017年 shan. All rights reserved.
////
//
//#import "IJSImageAPIManager.h"
//#import <AssetsLibrary/AssetsLibrary.h>
//static CGFloat JSScreenWidth;  //屏幕宽度
//static CGFloat JSScreenScale;   //缩放比例
//
//@implementation IJSImageAPIManager
//
//
//+(instancetype) shareManager
//{
//    static IJSImageAPIManager *manager = nil;
//    static dispatch_once_t onceToken;
//    dispatch_once(&onceToken, ^{
//        manager = [[self alloc] init];
//        JSScreenWidth = [[UIScreen mainScreen]bounds].size.width;
//        JSScreenScale = 2.0;
//        if (JSScreenWidth > 700)
//        {
//            JSScreenScale = 1.5;
//        }
//    });
//    return manager;
//}
///**
// *  授权
// */
//+(JSPhotoState)authorizationStatus;
//{
//    JSPhotoState status = JSAuthorizationStatusNotDetermined;
//    switch ([PHPhotoLibrary authorizationStatus])
//    {
//        case 0:
//            status = JSAuthorizationStatusNotDetermined;
//            break;
//        case 1:
//            status = JSAuthorizationStatusRestricted;
//            break;
//        case 2:
//            status = JSAuthorizationStatusDenied;
//            break;
//        case 3:
//            status = JSAuthorizationStatusAuthorized;
//            break;
//        default:
//            break;
//    }
//    return status;
//}
///**
// *  获取所有的PHasset
// */
//-(void)getAllAssetFromSourceType:(PHAssetSourceType)includeAssetSourceTypes sortDescriptors:(BOOL)sortDescriptors isAllowPickingImage:(BOOL)isAllowPickingImage isAllowPickingVideo:(BOOL)isAllowPickingVideo isAllowPickingAudio:(BOOL)isAllowPickingAudio isAllowPickingGif:(BOOL)isAllowPickingGif includeHiddenAssets:(BOOL)includeHiddenAssets  includeAllBurstAssets:(BOOL)includeAllBurstAssets fetchLimit:(NSInteger)fetchLimit completion:(void(^)(NSMutableArray *result))completion
//{
//    if (iOS8Later)
//    {
//        NSMutableArray *resultArr = [NSMutableArray array];
//        PHFetchOptions *options =[[PHFetchOptions alloc]init];
//        if (sortDescriptors) options.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:YES]];
//        options.includeAssetSourceTypes = includeAssetSourceTypes;
//        options.includeHiddenAssets = includeHiddenAssets;
//        options.includeAllBurstAssets = includeAllBurstAssets;
//        options.predicate = [NSPredicate predicateWithFormat:@"mediaType == %d || mediaType == %d || mediaType == %d || mediaType == %d",isAllowPickingImage?PHAssetMediaTypeImage:PHAssetMediaTypeUnknown,isAllowPickingVideo?PHAssetMediaTypeVideo:PHAssetMediaTypeUnknown,isAllowPickingAudio?PHAssetMediaTypeAudio:PHAssetMediaTypeUnknown,isAllowPickingGif?PHAssetMediaTypeImage:PHAssetMediaTypeImage];
//        options.fetchLimit = fetchLimit;
//        options.wantsIncrementalChangeDetails = YES;
//        dispatch_async(dispatch_get_global_queue(0, 0), ^{
//            PHFetchResult<PHAsset *> * result = [PHAsset fetchAssetsWithOptions:options];
//            for (PHAsset *asset  in result)
//            {
//                [resultArr insertObject:asset atIndex:0];
//            }
//            completion(resultArr);
//        });
//    }
//
//}
///**
// *  获取所有的相册,以及每一个相册对应的相册中的具体数据
// */
//-(void)getAllAssetFromAlbumSortDescriptors:(BOOL)sortDescriptors isAllowPickingImage:(BOOL)isAllowPickingImage isAllowPickingVideo:(BOOL)isAllowPickingVideo isAllowPickingAudio:(BOOL)isAllowPickingAudio isAllowPickingGif:(BOOL)isAllowPickingGif includeHiddenAssets:(BOOL)includeHiddenAssets  includeAllBurstAssets:(BOOL)includeAllBurstAssets completion:(void(^)(NSMutableArray<NSMutableDictionary *> *result))completion
//{
//    NSMutableArray *albumArr = [NSMutableArray array];
//    if (iOS8Later)  // ios 8  之后
//    {
//        PHFetchOptions *options =[[PHFetchOptions alloc]init];
//        if (sortDescriptors) options.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:YES]];
//        options.includeHiddenAssets = includeHiddenAssets;
//        options.includeAllBurstAssets = includeAllBurstAssets;
//        options.predicate = [NSPredicate predicateWithFormat:@"mediaType == %d || mediaType == %d || mediaType == %d || mediaType == %d",isAllowPickingImage?PHAssetMediaTypeImage:PHAssetMediaTypeUnknown,isAllowPickingVideo?PHAssetMediaTypeVideo:PHAssetMediaTypeUnknown,isAllowPickingAudio?PHAssetMediaTypeAudio:PHAssetMediaTypeUnknown,isAllowPickingGif?PHAssetMediaTypeImage:PHAssetMediaTypeImage];
//        options.wantsIncrementalChangeDetails = YES;
//        // 用户照片
//        PHFetchResult<PHCollection *> *topLevelUserCollections = [PHCollectionList fetchTopLevelUserCollectionsWithOptions:nil];
//
//        PHFetchResult<PHAssetCollection *> *myAllPhotoAlbum = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeAlbum subtype:PHAssetCollectionSubtypeAny options:nil];  // 所有的照片
//        PHFetchResult<PHAssetCollection *> *myPhotoStreamAlbum = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeAlbum subtype:PHAssetCollectionSubtypeAlbumMyPhotoStream options:nil]; //用户的 iCloud 照片流
//        PHFetchResult<PHAssetCollection *> *syncedAlbums = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeAlbum subtype:PHAssetCollectionSubtypeAlbumSyncedAlbum options:nil];  // 从iPhoto同步到设备的相册
//        PHFetchResult<PHAssetCollection *> *sharedAlbums = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeAlbum subtype:PHAssetCollectionSubtypeAlbumCloudShared options:nil]; //用户使用 iCloud 共享的相册
//
//        // 智能相册
//        PHFetchResult<PHAssetCollection *> *smartAlbums = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeSmartAlbum subtype:PHAssetCollectionSubtypeAlbumRegular options:nil];
//
//        NSArray *allAlbums = @[topLevelUserCollections,myAllPhotoAlbum,myPhotoStreamAlbum,syncedAlbums,sharedAlbums,smartAlbums];
//        for (PHFetchResult *fetchResult in allAlbums) {
//            for (PHAssetCollection *collection in fetchResult)
//            {
//                if (![collection isKindOfClass:[PHAssetCollection class]]) continue;    // 有可能是PHCollectionList类的的对象，过滤掉
//                PHFetchResult<PHAsset *> *fetchResult = [PHAsset fetchAssetsInAssetCollection:collection options:options];
//                if (fetchResult.count < 1) continue; // 过滤无照片的相册
//                if ([collection.localizedTitle containsString:@"Deleted"] || [collection.localizedTitle isEqualToString:@"最近删除"]) continue;
//
//                if ([self _isCameraRollAlbum:collection.localizedTitle]) // 相机胶卷放到第一个位置
//                {
//                    [albumArr insertObject:[self _sourceFromResult:collection name:collection.localizedTitle count:fetchResult.count asset:fetchResult] atIndex:0];
//                }
//                else  // 非相机胶卷
//                {
//                    [albumArr addObject:[self _sourceFromResult:collection name:collection.localizedTitle count:fetchResult.count asset:fetchResult]];
//                }
//            }
//        }
//        if (completion && albumArr.count > 0) completion(albumArr);
//    }
//    else   // ios 8 之前
//    {
//
//    }
//}
///*-----------------------------------解析 asset 获取原始图-------------------------------------------------------*/
//-(void) getImageFromAsset:(PHAsset *)asset targetSizeWidth:(CGFloat)targetSizeWidth contentMode:(PHImageContentMode)contentMode options:(PHImageRequestOptions *)options networkAccessAllowed:(BOOL)networkAccessAllowed completion:(void (^)(UIImage *photo,NSDictionary *info,BOOL isDegraded))completion progressHandler:(void (^)(double progress, NSError *error, BOOL *stop, NSDictionary *info))progressHandler
//{
//    if (iOS8Later)
//    {
//        PHAsset *phAsset = (PHAsset *)asset;
//        CGFloat aspectRatio = phAsset.pixelWidth / (CGFloat)phAsset.pixelHeight;
//        CGFloat pixelWidth = targetSizeWidth * JSScreenScale;
//        CGFloat pixelHeight = pixelWidth / aspectRatio;
//        CGSize imageSize = CGSizeMake(pixelWidth, pixelHeight);
//
//        PHImageRequestOptions *needOptions = nil;
//        // 请求资源的限制
//        if (options == nil)
//        {
//            PHImageRequestOptions *reoptions =[[PHImageRequestOptions alloc]init];
//            reoptions.version = PHImageRequestOptionsVersionOriginal; // 原始图
//            reoptions.deliveryMode = PHImageRequestOptionsDeliveryModeHighQualityFormat; // 图片的请求质量
//            reoptions.resizeMode = PHImageRequestOptionsResizeModeFast;  // 缩略图PHImageRequestOptionsResizeModeExact
//            reoptions.normalizedCropRect = CGRectZero;  // 裁剪尺寸
//
//            needOptions = reoptions;
//        }
//        else
//        {
//            needOptions = options;
//        }
//        [[PHImageManager defaultManager]requestImageForAsset:asset targetSize:imageSize contentMode:PHImageContentModeAspectFill options:needOptions resultHandler:^(UIImage * _Nullable result, NSDictionary * _Nullable info) {
//            // 排除取消，错误，低清图三种情况，即已经获取到了高清图
//            BOOL downloadFinined = (![[info objectForKey:PHImageCancelledKey] boolValue] && ![info objectForKey:PHImageErrorKey]);
//            if (downloadFinined && result)  // 已经获取本地的缩略图
//            {
//                if (completion) completion(result,info,[[info objectForKey:PHImageResultIsDegradedKey] boolValue]);
//            }
//            if ([info objectForKey:PHImageResultIsInCloudKey] && !result && networkAccessAllowed)  //请求来自网络包括
//            {
//                PHImageRequestOptions *options = [[PHImageRequestOptions alloc] init];
//                options.progressHandler = ^(double progress, NSError *error, BOOL *stop, NSDictionary *info) {
//                    dispatch_async(dispatch_get_main_queue(), ^{
//                        if (progressHandler) {
//                            progressHandler(progress, error, stop, info);
//                        }
//                    });
//                };
//                options.networkAccessAllowed = YES;       // 允许网络请求
//                options.resizeMode = PHImageRequestOptionsResizeModeFast;   //速度最快的方式
//                [[PHImageManager defaultManager]requestImageDataForAsset:asset options:options resultHandler:^(NSData * _Nullable imageData, NSString * _Nullable dataUTI, UIImageOrientation orientation, NSDictionary * _Nullable info) {
//                    UIImage *resultImage = [UIImage imageWithData:imageData scale:1];
//                    resultImage = [self scaleImage:resultImage toSize:imageSize];
//                    if (resultImage)
//                    {
//                        if (completion) completion(resultImage,info,[[info objectForKey:PHImageResultIsDegradedKey] boolValue]);
//                    }
//                }];
//            }
//        }];
//    }
//    else   // ios 8 之前
//    {
//
//    }
//}
///*-----------------------------------将相册数据解析PHAsset数组-------------------------------------------------------*/
//- (void)getAssetsFromFetchResult:(id)result allowPickingVideo:(BOOL)allowPickingVideo allowPickingImage:(BOOL)allowPickingImage ascending:(BOOL)ascending completion:(void (^)(NSArray<NSMutableDictionary *> *models))completion
//{
//    NSMutableArray *photoArr = [NSMutableArray array];
//    if ([result isKindOfClass:[PHFetchResult class]])    //  8之后
//    {
//        PHFetchResult *fetResult = (PHFetchResult *)result;
//        [fetResult enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
//            NSMutableDictionary *modelDic = [self _setModelWithAsset:obj allowPickingVideo:allowPickingVideo allowPickingImage:allowPickingImage];
//            if (modelDic)
//            {
//                [photoArr addObject:modelDic];
//            }
//        }];
//        if (completion)
//        {
//            completion(photoArr);
//        }
//    }
//    else if ([result isKindOfClass:[ALAssetsGroup class]])   //8之前
//    {
//        ALAssetsGroup *group = (ALAssetsGroup *)result;
//        if (allowPickingImage && allowPickingVideo)
//        {
//            [group setAssetsFilter:[ALAssetsFilter allAssets]];
//        }
//        else if (allowPickingVideo)
//        {
//            [group setAssetsFilter:[ALAssetsFilter allVideos]];
//        }
//        else if (allowPickingImage)
//        {
//            [group setAssetsFilter:[ALAssetsFilter allPhotos]];
//        }
//        ALAssetsGroupEnumerationResultsBlock resultBlock = ^(ALAsset *result, NSUInteger index, BOOL *stop)  {
//            if (result == nil)
//            {
//                if (completion) completion(photoArr);
//            }
//            NSMutableDictionary *modelDic  = [self _setModelWithAsset:result allowPickingVideo:allowPickingVideo allowPickingImage:allowPickingImage];
//            if (modelDic)
//            {
//                [photoArr addObject:modelDic];
//            }
//        };
//
//        if (ascending)
//        {
//            [group enumerateAssetsUsingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop) {
//                if (resultBlock) { resultBlock(result,index,stop); }
//            }];
//        }
//        else
//        {
//            [group enumerateAssetsWithOptions:NSEnumerationReverse usingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop) {
//                if (resultBlock) { resultBlock(result,index,stop); }
//            }];
//        }
//    }
//}
//// 获得下标为index的单个照片 如果索引越界, 在回调中返回 nil
//- (void)getAssetFromFetchResult:(id)result atIndex:(NSInteger)index allowPickingVideo:(BOOL)allowPickingVideo allowPickingImage:(BOOL)allowPickingImage ascending:(BOOL)ascending completion:(void (^)(NSMutableDictionary *model))completion
//{
//    if ([result isKindOfClass:[PHFetchResult class]])
//    {
//        PHFetchResult *fetchResult = (PHFetchResult *)result;
//        PHAsset *asset;
//        @try {
//            asset = fetchResult[index];
//        }
//        @catch (NSException* e) {
//            if (completion) completion(nil);
//            return;
//        }
//        @finally {
//            NSLog(@"获取的下标数组越界了");
//        }
//        NSMutableDictionary *model = [self _setModelWithAsset:result allowPickingVideo:allowPickingVideo allowPickingImage:allowPickingImage];;
//        if (completion) completion(model);
//    }
//    else if ([result isKindOfClass:[ALAssetsGroup class]])
//    {
//        ALAssetsGroup *group = (ALAssetsGroup *)result;
//        if (allowPickingImage && allowPickingVideo)
//        {
//            [group setAssetsFilter:[ALAssetsFilter allAssets]];
//        }
//        else if (allowPickingVideo)
//        {
//            [group setAssetsFilter:[ALAssetsFilter allVideos]];
//        }
//        else if (allowPickingImage)
//        {
//            [group setAssetsFilter:[ALAssetsFilter allPhotos]];
//        }
//        NSIndexSet *indexSet = [NSIndexSet indexSetWithIndex:index];
//        @try {
//            [group enumerateAssetsAtIndexes:indexSet options:NSEnumerationConcurrent usingBlock:^(ALAsset *result, NSUInteger index, BOOL *stop) {
//                if (!result) return;
//                NSMutableDictionary *model = [self _setModelWithAsset:result allowPickingVideo:allowPickingVideo allowPickingImage:allowPickingImage];;
//                if (completion) completion(model);
//            }];
//        }
//        @catch (NSException* e) {
//            if (completion) completion(nil);
//        }
//        @finally {
//            NSLog(@"获取的下标数组越界了");
//        }
//    }
//}
//#pragma mark 获取当前app自定义的相册
//// 外部统一的接口
//+ (void) imageSaveIntoAlbumFromImage:(UIImage *)image albumName:(NSString *)albumName onSaveStateChanged:(JSPhotoChangeHandler)saveStateBlock
//{
//    if (iOS8Later)
//    {
//        PHAuthorizationStatus oldStatus =[PHPhotoLibrary authorizationStatus];  //获取授权状态
//        [PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {  //判断是否授权
//            if (status == PHAuthorizationStatusDenied)  // 用户拒绝访问当前相册
//            {
//                if (oldStatus != PHAuthorizationStatusNotDetermined)  // 提醒打开开关
//                {
//                    saveStateBlock(JSAuthorizationStatusNotDetermined,nil);
//                }
//            }
//            else if (status == PHAuthorizationStatusAuthorized) // 允许访问
//            {
//                [self isOverAuthorizationSaveIntoAlbumFromImage:image albumName:albumName OnSaveStateChanged:saveStateBlock];
//            }
//            else if (status == PHAuthorizationStatusRestricted) // 无法访问
//            {
//                saveStateBlock(JSAuthorizationStatusRestricted,nil);
//            }
//        }];
//    }
//    else    //  8 之前
//    {
//
//    }
//}
//#pragma mark 将照片保存到自定义的相册
//// 将照片保存到相册
//+(void) isOverAuthorizationSaveIntoAlbumFromImage:(UIImage *)image albumName:(NSString *)albumName OnSaveStateChanged:(JSPhotoChangeHandler)saveStateBlock
//{
//    // 获取保存相机胶卷中的图片
//    PHFetchResult<PHAsset *> *createdAssets = [self createdAssetsFromImage:image onSaveStateChanged:saveStateBlock];
//    if (createdAssets == nil)
//    {
//        saveStateBlock(JSCreatedAlbumFail,nil); //创建相册失败了
//        return;
//    }
//    // 2, 拥有一个自定义相册
//    PHAssetCollection *phCollections = [self createdPHAssetCollectionFromAlbumName:albumName onSaveStateChanged:saveStateBlock];
//    if (phCollections == nil) //创建或者获取相册失败
//    {
//        saveStateBlock(JSCreatedAlbumFail,nil);
//        return;
//    }
//    // 3,添加刚才保存的图片到自定义相册
//    NSError *error =nil;
//    [[PHPhotoLibrary sharedPhotoLibrary]performChangesAndWait:^{
//        PHAssetCollectionChangeRequest *request = [PHAssetCollectionChangeRequest changeRequestForAssetCollection:phCollections];
//        [request insertAssets:createdAssets atIndexes:[NSIndexSet indexSetWithIndex:0]]  ;
//    } error:&error];
//    if (error)  //保存图片失败
//    {
//        saveStateBlock(JSSaveImageFail,error);
//    }
//    else  // 保存图片成功
//    {
//        saveStateBlock(JSSaveImageSuccess,nil);
//    }
//}
//
//// 获取保存到相册中图片
//+ (PHFetchResult<PHAsset *> *) createdAssetsFromImage:(UIImage *)image onSaveStateChanged:(JSPhotoChangeHandler)saveStateBlock
//{
//    NSError *error = nil;
//    // 1,保存图片到相机胶卷
//    __block NSString *assetID = nil;
//    [[PHPhotoLibrary sharedPhotoLibrary] performChangesAndWait:^{
//        assetID = [PHAssetChangeRequest creationRequestForAssetFromImage:image].placeholderForCreatedAsset.localIdentifier;
//    } error:&error];
//    if (error)
//    {
//        saveStateBlock(JSCreatedAlbumFail,error);
//        return nil;
//    }
//    // 获取相片
//    return  [PHAsset fetchAssetsWithLocalIdentifiers:@[assetID] options:nil];
//}
//
//// 创建自定义相册
//+ (PHAssetCollection *) createdPHAssetCollectionFromAlbumName:(NSString *)albumName onSaveStateChanged:(JSPhotoChangeHandler)saveStateBlock
//{
//    // 查询
//    //1 查询
//    /*
//     PHAssetCollectionTypeAlbum      = 1,    自定义相册
//     PHAssetCollectionTypeSmartAlbum = 2,   智能相册,系统自带相册
//     PHAssetCollectionTypeMoment     = 3,  时间分
//     */
//    PHFetchResult<PHAssetCollection *> *fetchResult = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeAlbum subtype:PHAssetCollectionSubtypeAlbumRegular options:nil];
//    for (PHAssetCollection *collections in fetchResult)
//    {
//        if ([collections.localizedTitle isEqualToString:albumName])
//        {
//            return collections;
//        }
//    }
//    /* 没有创建过相册 */
//    //2 创建自己相册的 唯一标识,生成占位对象
//    NSError *error = nil;
//    __block NSString *photoID = nil;
//    [[PHPhotoLibrary sharedPhotoLibrary] performChangesAndWait:^{
//        photoID = [PHAssetCollectionChangeRequest creationRequestForAssetCollectionWithTitle:albumName].placeholderForCreatedAssetCollection.localIdentifier;
//    } error:&error];
//    if (error)
//    {
//        saveStateBlock(JSPhotosNoNeed,error);
//        return nil;
//    }
//    // 创建相册成功,并返回
//    return  [PHAssetCollection fetchAssetCollectionsWithLocalIdentifiers:@[photoID] options:nil].firstObject;
//}
///*-----------------------------------私有方法-------------------------------------------------------*/
//#pragma mark 私有方法
//// 判断是否是相机胶卷
//- (BOOL)_isCameraRollAlbum:(NSString *)albumName
//{
//    NSString *versionStr = [[UIDevice currentDevice].systemVersion stringByReplacingOccurrencesOfString:@"." withString:@""];
//    if (versionStr.length <= 1)
//    {
//        versionStr = [versionStr stringByAppendingString:@"00"];
//    }
//    else if (versionStr.length <= 2)
//    {
//        versionStr = [versionStr stringByAppendingString:@"0"];
//    }
//    CGFloat version = versionStr.floatValue;
//    // 目前已知8.0.0 - 8.0.2系统，拍照后的图片会保存在最近添加中
//    if (version >= 800 && version <= 802)
//    {
//        return [albumName isEqualToString:@"最近添加"] || [albumName isEqualToString:@"Recently Added"];
//    }
//    else
//    {
//        return [albumName isEqualToString:@"Camera Roll"] || [albumName isEqualToString:@"相机胶卷"] || [albumName isEqualToString:@"所有照片"] || [albumName isEqualToString:@"All Photos"];
//    }
//}
//
//-(NSMutableDictionary *)_sourceFromResult:(PHAssetCollection *)collection name:(NSString *)name count:(NSInteger )count asset:(PHFetchResult<PHAsset *>*)asset
//{
//    NSMutableDictionary *albumDic =[NSMutableDictionary dictionary];
//    [albumDic setValue:asset forKey:@"asset"];
//    [albumDic setValue:collection.localizedTitle forKey:@"localizedTitle"];
//    [albumDic setValue:collection forKey:@"collection"];
//    [albumDic setValue:[NSString stringWithFormat:@"%ld",(long)count] forKey:@"count"];
//    return albumDic;
//}
//
//- (UIImage *)scaleImage:(UIImage *)image toSize:(CGSize)size
//{
//    if (image.size.width > size.width)
//    {
//        UIGraphicsBeginImageContext(size);
//        [image drawInRect:CGRectMake(0, 0, size.width, size.height)];
//        UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
//        UIGraphicsEndImageContext();
//        return newImage;
//    }
//    else
//    {
//        return image;
//    }
//}
///*-----------------------------------解析相册私有方法-------------------------------------------------------*/
///// 设置图片的model
//-(NSMutableDictionary *)_setModelWithAsset:(id)asset allowPickingVideo:(BOOL)allowPickingVideo allowPickingImage:(BOOL)allowPickingImage
//{
//    NSMutableDictionary *modelDic =[NSMutableDictionary dictionary];
//    JSAssetModelSourceType type = JSAssetModelMediaTypePhoto;
//    if ([asset isKindOfClass:[PHAsset class]])   // PHAsset类型
//    {
//        PHAsset *phAsset = (PHAsset *)asset;
//        if (phAsset.mediaType == PHAssetMediaTypeVideo)      type = JSAssetModelMediaTypeVideo;
//        else if (phAsset.mediaType == PHAssetMediaTypeAudio) type = JSAssetModelMediaTypeAudio;
//        else if (phAsset.mediaType == PHAssetMediaTypeImage)
//        {
//            if (iOS9_1Later)  //PhotoLive
//            {
//                if (phAsset.mediaSubtypes == PHAssetMediaSubtypePhotoLive) type = JSAssetModelMediaTypeLivePhoto;
//            }
//            // Gif
//            if ([[phAsset valueForKey:@"filename"] hasSuffix:@"GIF"])
//            {
//                type = JSAssetModelMediaTypePhotoGif;
//            }
//        } // 判断资源类型结束
//        if (!allowPickingVideo && type == JSAssetModelMediaTypeVideo) return nil;
//        if (!allowPickingImage && type == JSAssetModelMediaTypePhoto) return nil;
//        if (!allowPickingImage && type == JSAssetModelMediaTypePhotoGif) return nil;
//        if (!allowPickingImage && type == JSAssetModelMediaTypeLivePhoto) return nil;  //LivePhoto
//
//
//        NSString *timeLength = type == JSAssetModelMediaTypeVideo ? [NSString stringWithFormat:@"%0.0f",phAsset.duration] : @"";
//        timeLength = [self getNewTimeFromDurationSecond:timeLength.integerValue];  //需要的格式显示
//        modelDic =[self _setAssetModelDicAsset:asset type:type timeLength:timeLength];
//    }
//    else
//    {
//        if (!allowPickingVideo)
//        {
//            modelDic =[self _setAssetModelDicAsset:nil type:type timeLength:nil];
//            return modelDic;
//        }
//        /// 允许选择视频
//        if ([[asset valueForProperty:ALAssetPropertyType] isEqualToString:ALAssetTypeVideo])  //是视频
//        {
//            type = JSAssetModelMediaTypeVideo;
//            NSTimeInterval duration = [[asset valueForProperty:ALAssetPropertyDuration] integerValue];
//            NSString *timeLength = [NSString stringWithFormat:@"%0.0f",duration];
//            timeLength = [self getNewTimeFromDurationSecond:timeLength.integerValue];
//            modelDic = [self _setAssetModelDicAsset:asset type:type timeLength:timeLength];
//        }
//        else   // 图片
//        {
//            modelDic =[self  _setAssetModelDicAsset:asset type:type timeLength:nil];
//        }
//    }
//    return modelDic;
//}
//// 解析获取到的视频时间为需要的数据
//- (NSString *)getNewTimeFromDurationSecond:(NSInteger)duration
//{
//    NSString *newTime;
//    if (duration < 10)
//    {
//        newTime = [NSString stringWithFormat:@"0:0%zd",duration];
//    }
//    else if (duration < 60)
//    {
//        newTime = [NSString stringWithFormat:@"0:%zd",duration];
//    }
//    else
//    {
//        NSInteger min = duration / 60;
//        NSInteger sec = duration - (min * 60);
//        if (sec < 10)
//        {
//            newTime = [NSString stringWithFormat:@"%zd:0%zd",min,sec];
//        }
//        else
//        {
//            newTime = [NSString stringWithFormat:@"%zd:%zd",min,sec];
//        }
//    }
//    return newTime;
//}
///// 设置返回的数据参数
//-(NSMutableDictionary *)_setAssetModelDicAsset:(id)asset type:(JSAssetModelSourceType)type timeLength:(NSString *)timeLength
//{
//    NSMutableDictionary *modelDic =[NSMutableDictionary dictionary];
//    [modelDic setObject:asset forKey:@"asset"];
//    [modelDic setObject:[NSString stringWithFormat:@"%lu",(unsigned long)type]  forKey:@"type"];
//    [modelDic setObject:timeLength forKey:@"timeLength"];
//    return modelDic;
//}
//
//
//
//#pragma mark set    方法
//-(void)setSortAscendingByModificationDate:(BOOL)sortAscendingByModificationDate
//{
//    _sortAscendingByModificationDate = sortAscendingByModificationDate;
//}
//
//
//
//
//
//
//
//
//
//
//
//@end
